package com.epalmpay.controller.channel.member;

import com.epalmpay.commom.BaseController;
import com.epalmpay.dto.bonus.BonusSendLogInDTO;
import com.epalmpay.dto.bonus.BonusSendLogListOutDTO;
import com.epalmpay.dto.memberGrade.MemberGradeInDTO;
import com.epalmpay.dto.memberGrade.MemberGradeOutDTO;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.dto.xyMemberGrade.XyMemberGradeInDTO;
import com.epalmpay.dto.xyMemberGrade.XyMemberGradeListOutDTO;
import com.epalmpay.dto.xyMemberGrade.XyMemberGradeOutDTO;
import com.epalmpay.entity.MemberGrade;
import com.epalmpay.entity.Page;
import com.epalmpay.entity.XyMemberGrade;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.service.member.IXyMemberGradeService;
import com.epalmpay.status.Rescode;
import com.epalmpay.util.PropertyCopyUtil;
import com.epalmpay.util.Tools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.awt.SunHints;

import javax.annotation.Resource;

/**
 * Created by gwn on 2017/12/25.
 */
@Controller
@RequestMapping(value="/channel/xyMemberGrade")
public class XyMemberGradeController extends BaseController{

    @Resource
    private IXyMemberGradeService xyMemberGradeService;

    @ResponseBody
    @RequestMapping(value = "/list")
    public XyMemberGradeListOutDTO list(XyMemberGradeInDTO xyMemberGradeInDTO, PageDTO pageDTO)throws Exception{
        XyMemberGradeListOutDTO xyMemberGradeListOutDTO = new XyMemberGradeListOutDTO();
        try {
            Page page= Tools.pageEmtity(pageDTO);
            xyMemberGradeListOutDTO= xyMemberGradeService.queryXyMemberGradeList(xyMemberGradeInDTO,page);

            xyMemberGradeListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");

            xyMemberGradeListOutDTO.setPage(page);
            return xyMemberGradeListOutDTO;
        } catch (ApplicationException ae) {
            xyMemberGradeListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            xyMemberGradeListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return xyMemberGradeListOutDTO;

    }


    /**
     * 通过会员id查询会员等级详情
     *
     */
    @RequestMapping(value="/queryXymemberGrade")
    @ResponseBody
    public XyMemberGradeOutDTO findMemberGradeById(XyMemberGradeInDTO xyMemberGradeInDTO){
        XyMemberGradeOutDTO xyMemberGradeOutDTO=null;
        XyMemberGrade xyMemberGrade=new XyMemberGrade();
        try {
            xyMemberGrade.setId(xyMemberGradeInDTO.getId());
             xyMemberGradeOutDTO =xyMemberGradeService.queryXyMemberGradeDetail(xyMemberGrade);

            xyMemberGradeOutDTO.setErrorCode(Rescode.SUCCESS, "查询成功");
            return xyMemberGradeOutDTO;

        } catch (ApplicationException ae) {
            xyMemberGradeOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }catch (Exception e) {
            xyMemberGradeOutDTO.setErrorCode("-1", "处理出现异常");
            e.printStackTrace();
        }
        xyMemberGradeOutDTO.setErrorCode("-2", "处理失败");
        return xyMemberGradeOutDTO;
    }


}
